Skip to content

Conversation

dariuszkuc
Copy link
Member

@dariuszkuc dariuszkuc commented Aug 26, 2025

Updates SchemaBuilder to allow SDL to contain built-in meta types (e.g. __Type) redefinitions. GraphQL spec doesn't really define the expected behavior for handling SDL with redeclared meta fields (see: #1036, #1049). graphql-js reference implementation simply ignores those redefinitions even if the underlying type definitions don't match.

This PR updates ignore_builtin_redefinitions option to also ignore meta types redefinitions (previously it was only allowing built-in scalar redefinitions #990).

Updates `SchemaBuilder` to allow SDL to contain built-in meta types (e.g. `__Type`) redefinitions. GraphQL spec doesn't really define the expected behavior for handling SDL with redeclared meta fields (see: [#1036](graphql/graphql-spec#1036), [#1049](graphql/graphql-spec#1049)). `graphql-js` [reference implementation](https://github.com/graphql/graphql-js/blob/v16.11.0/src/utilities/extendSchema.ts#L187) simply ignores those redefinitions even if the underlying type definitions don't match.

This PR updates `ignore_builtin_redefinitions` option to also ignore meta types redefinitions (previously it was only allowing built-in scalar redefinitions #990).
@dariuszkuc dariuszkuc requested a review from a team as a code owner August 26, 2025 17:03
@dariuszkuc dariuszkuc enabled auto-merge (squash) August 26, 2025 17:05
"#;

let errors = Schema::parse_and_validate(schema, "schema.graphql")
.expect_err("valid schema")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i changed the message here (before it said "invalid schema"). expect_err panics when an Err is expected but we got an Ok. So here, instead of getting an invalid schema, we actually get a valid one.

Copy link
Member

@lrlna lrlna Aug 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh, no, ignore me, invalid schema was correct! i'll change this back in a follow up PR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fyi the meta type definition for __Directive was incorrect (on purpose) with nullable arg vs non nun list of non null args. This was to show that we just ignore those redefinitions even if they dont match.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left it as incorrect, and all the other types I added were also slightly incorrect. A bit harder with scalars, so scalars are all the same.

}

#[test]
fn handles_built_in_type_redefinition() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This types.rs file was for ValuesOfCorrectType Rule tests, so I moved these builtin_type_redefinition tests into their own file.

#[test]
fn handles_built_in_scalar_redefinition() {
let schema = r#"
scalar String
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we are extra sure, I added all the scalar redefinitions and all the type redefinitions (below).

@dariuszkuc dariuszkuc merged commit febe8d3 into main Aug 27, 2025
12 checks passed
@dariuszkuc dariuszkuc deleted the dk/builtin_redefinition branch August 27, 2025 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants